#!/bin/sh

# 生成配置文件
ip=$(giddyup ip myip)
echo get my ip: $ip
helm template --set pdName=$ip,advertiseClientUrls=$ip:2379,advertisePeerUrls=$ip:2380 /tidb -x templates/pd.toml | sed 's/---//g' > /pd.toml

cat /pd.toml

# 表明它是被人加入的节点
giddyup leader check
if [ "$?" -eq "0" ];then
    echo "I'm the first node"
    /pd-server --config=/pd.toml
else
    leaderip=$(giddyup leader get)
    echo get leader $leaderip
    /pd-server --config=/pd.toml --join=http://${leaderip}:2379
fi
